<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/html5.js"></script>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/respond.min.js"></script>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="<?=base_url('publics/admin');?>/style/styles.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url('publics/admin');?>/lib/font-awesome/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="<?=base_url('publics/admin');?>/lib/font-awesome/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="<?=base_url('publics/admin');?>/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script type="text/javascript" src="<?php echo base_url('publics')?>/admin/editor/kindeditor.js"></script>     
<script type="text/javascript" src="<?php echo base_url('publics')?>/admin/editor/lang/zh_CN.js"></script>
<title>产品属性值</title> 
</head>
<body>
<div id="main_right">
  <div id="r_title">
    <div id="r_title_content">
      产品管理 &gt; 增加产品属性值
    </div>
  </div>
  
  <div id="r_menu">
    <ul>
      <li><a class="btn btn-primary radius" href="<?=base_url('manage/product');?>">返回产品列表</a></li>
    </ul>
  </div>
    <div class="line_white"></div>
  <div id="r_list">
   <?php echo validation_errors(); ?>
    <form action="" method="post" class="form form-horizontal" id="form-menu-add"  >
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>产品名：</label>
      <div class="formControls col-5">
        <?=$attr['pro_name'];?>
      </div>
      <div class="col-4"> </div>
    </div>    
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red"></span>产品属性名：</label>
      <div class="formControls col-5">
        <?=$attr['attr_name'];?>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>选择地区：</label>
      <div class="formControls col-5">
        <select class="province" datatype="*" nullmsg="请选择所在城市！" name="province" >
            <option value="0">-- 请选择省 --</option>
            <?=$province;?>
        </select>
        <select class="city" name="city">
          <option value="0">-- 请选择城市 --</option>
        </select>
        <select class="area" name="area">
          <option value="0">-- 请选择区县 --</option>
        </select>

      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>区域价格：</label>
      <div class="formControls col-5">
      <input type="text" size="30"  class="input-text" nullmsg="价格不能为空" name="price" id="price" placeholder=""  value="1" datatype="*1-16"/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>排序：</label>
      <div class="formControls col-5">
        <input type="number" size="30" value="1" name="sort" id="sort" placeholder=""  datatype="*1-200" class="input-text" nullmsg="排序不能为空"/>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>状态：</label>
      <div class="formControls col-5 skin-minimal">
        <div class="radio-box">
          <input type="radio" id="sex-1" name="reg_status" value="1" checked="checked" datatype="*" nullmsg="请选择状态！">
          <label for="sex-1">有效</label>
        </div>
        <div class="radio-box">
          <input type="radio" id="sex-2" value="0" name="reg_status">
          <label for="sex-2">无效</label>
        </div>
      </div>
      <div class="col-4"> </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input class="btn btn-primary radius" type="botton" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="return check_from();">
      </div>
    </div>
    <input type="hidden" value="<?=$attr['pro_id'];?>" name="pro_id" id="pro_id">
    <input type="hidden" value="<?=$attr['attr_id'];?>" name="attr_id" id="attr_id">
  </form>
  </div>

  <div style="margin-top:50px;">
     <table class="table table-border table-bordered table-hover table-bg">
      <thead>
        <tr class="text-c">
          <th width="300">地区名</th>
          <th>价格/元</th>
          <th width="70">排序</th>
          <th width="70">状态</th>
          <th width="70">操作</th>
        </tr>
      </thead>
      <tbody>
        <?php if($value):?>
        <?php foreach($value as $val):?>
        <tr class="text-c">
          <td>
            <?=$val['region'];?>
          </td>
          <td><input type="text" size="30"  class="input-text" nullmsg="价格不能为空"  value="<?=$val['reg_price'];?>" id="reg_price_<?=$val['reg_id'];?>" onchange="update_status(<?=$val['reg_id'];?>);"/></td>
          <td>
            <input type="number" value="<?=$val['reg_sort'];?>" size="30" value="1" name="reg_sort"  id="reg_sort_<?=$val['reg_id'];?>"  placeholder=""  datatype="*1-200" class="input-text" nullmsg="排序不能为空" onchange="update_status(<?=$val['reg_id'];?>);"/>
          </td>
          <td>
              <select name="status" onchange="update_status(<?=$val['reg_id'];?>);" id="reg_status_<?=$val['reg_id'];?>">
                <option value="1" <?php if($val['reg_status'] == 1):?>selected<?php endif;?>>有效</option>
                <option value="0" <?php if($val['reg_status'] == 0):?>selected<?php endif;?>>无效</option>
              </select>
          </td>
          <td>
            <a title="删除" href="javascript:;"  onclick="return deldata(<?=$val['reg_id'];?>);" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a>
          </td>
        </tr>
        <?php endforeach;?>
      <?php endif;?>
      </tbody>
    </table>
  </div>
</div>
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/jquery.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/layer1.8/layer.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/laypage/laypage.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/lib/Validform_v5.3.2.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/js/H-ui.js"></script> 
<script type="text/javascript" src="<?=base_url('publics/admin');?>/js/H-ui.admin.js"></script> 
<script type="text/javascript">
$(function(){
	$("#form-menu-add").Validform({
		tiptype:2,
	});
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});

  $('.province').change(
    function(){
      var id = $('.province').val();
      if(id == 0){
        alert('请选择省份!');
        return false;
      }
      $.ajax({
        type  : 'GET',
        url     :   '<?=base_url('manage');?>/region/getcity',
        data  : {'id':id},
        success : function(msg)
        {
          $(".city").html('');   // 清空里面html
          $(".city").prepend("<option value='0'>-- 城市 --</option>");
          $(".city").append(msg);//替换里面的内容
        }
      });
    }
  );


  $('.city').change(
    function(){
      var id = $('.city').val();
      if(id == 0){
        alert('请选择区县!');
        return false;
      }
      $.ajax({
        type  : 'GET',
        url     :   '<?=base_url('manage');?>/region/getcity',
        data  : {'id':id},
        success : function(msg)
        {
          $(".area").html('');   // 清空里面html
          $(".area").prepend("<option value='0'>-- 区县 --</option>");
          $(".area").append(msg);//替换里面的内容
        }
      });
    }
  );

});




function check_from(){ // 增加属性值
  var valData = {
      'pro_id'      :  $('#pro_id').val(),
      'attr_id'     :  $('#attr_id').val(),
      'reg_pid'     :  $('.province').val(),
      'reg_cid'     :  $('.city').val(),
      'reg_did'     :  $('.area').val(),
      'reg_price'   :  $('#price').val(),
      'reg_sort'    :  $('#sort').val(),
      'reg_status'  :  $('input[name="reg_status"]:checked').val()
  }
  
  $.ajax({
        type : 'POST',
        url  : '<?=base_url('manage/value/insert_region');?>',
        data : valData,
        success:function(msg){
          if(msg == 'ok'){
            alert('增加成功!');
            location.href = '/manage/value/insert?pid='+<?php echo $attr['pro_id'];?>+'&aid='+<?php echo $attr['attr_id'];?>;
          }
        }
  });
}

function deldata(id){
  $.layer({
      shade: [0],
      area: ['auto','auto'],
      dialog: {
          msg: '确定要删除该属性值吗？',
          btns: 2,                    
          type: 4,
          btn: ['是','否'],
          yes: function(){
          $.get("/manage/value/region_delete?id="+id,function(res){
              if(res == 'ok'){
                layer.msg('删除成功!', 1, 1);
                location.reload();
              }else{
                layer.msg('删除失败!', 1, 3);
              }
          });
          }, no: function(){}
      }
  });
}



function update_status(id){
  var regData = {
      'reg_sort'   :  $('#reg_sort_'+id).val(),
      'reg_price'  :  $('#reg_price_'+id).val(),
      'reg_status' :  $('#reg_status_'+id).val()
  }
  $.ajax({
      type : 'POST',
      url  : '<?=base_url('manage/value/update_region');?>?id='+id,
      data : regData,
      success:function(msg){
        if(msg == 'ok'){
           location.href = '';
        }else{
           layer.msg('修改失败,请联系网站管理员,');
        }
       
      }
  });
}
</script> 
</body>
</html>